//
//  InterstitialVC.m
//  CJModileAdDemo
//
//  Created by CJ on 2022/3/7.
//

#import "InterstitialVC.h"
#import <CJMobileAd/CJMobileAd.h>
#import "CustomShowView.h"
#import <AMPSAdSDK/AMPSAdSDK.h>

@interface InterstitialVC ()<AMPSInterstitialAdDelegate>

@property (nonatomic, strong) AMPSInterstitialAd *interstitialAd;

@end

@implementation InterstitialVC

@synthesize customView = _customView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)loadAdData {
    [self.interstitialAd loadInterstitialAd];
}

- (void)setupUI {
    self.title = @"InterstitialAd";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        NSLog(@"事件:%s", __FUNCTION__);
        [self loadAdData];
        return;
    }
}

- (AMPSInterstitialAd *)interstitialAd {
    if (!_interstitialAd) {
        _interstitialAd = [[AMPSInterstitialAd alloc] initWithSpaceId:@"124545" adConfiguration:[AMPSAdConfiguration new]];
        _interstitialAd.delegate = self;
    }
    return _interstitialAd;
}


- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak InterstitialVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark BUNativeExpressFullscreenVideoAdDelegate
- (void)ampsInterstitialAdLoadSuccess:(AMPSInterstitialAd *)interstitialAd {
    [self.interstitialAd showInterstitialAdWithRootViewController:self];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsInterstitialAdLoadFail:(AMPSInterstitialAd *)interstitialAd
                             error:(NSError *_Nullable)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsInterstitialAdDidShow:(AMPSInterstitialAd *)interstitialAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsInterstitialAdDidClick:(AMPSInterstitialAd *)interstitialAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsInterstitialAdDidClose:(AMPSInterstitialAd *)interstitialAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

@end
